package org.paradise.dms.dao.impl;

import java.util.List;

import org.paradise.dms.pojo.SystemUser;
import org.paradise.dms.pojo.SystemUserGroup;
import org.paradise.dms.pojo.SystemUserGroupRole;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.BaseHibernateDao;
import com.dheaven.framework.dao.DaoException;

/**
 * 
 * Description: 用户登录和权限值获取
 * 
 * Copyright (c) 2008-2009 paraDise sTudio(DT). All Rights Reserved.
 * 
 * @version 1.0 2009-3-8 下午06:35:25 李双江（paradise.lsj@gmail.com）created
 */
@Service
public class AuthenticateDAOImpl extends BaseHibernateDao<SystemUser> {

	/**
	 * 
	 * Description:根据用户名或昵称和密码和用户组类别进行登陆
	 * 
	 * @Version1.0 2009-3-8 下午06:48:29 李双江（paradise.lsj@gmail.com）创建
	 * @param name
	 * @param pwd
	 * @param roleType
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<SystemUser> findSysUserByNamePwd(String name, String pwd) {
		List<SystemUser> list = null;
		try {
			list = this.find("from SystemUser where (systemusername=? or systemusernickname=?) and systemuserpassword=? ", new Object[] { name, name, pwd, });
		} catch (DaoException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 
	 * Description:根据groupid查询用户权限值字符串
	 * 
	 * @Version1.0 2009-3-8 下午07:08:00 李双江（paradise.lsj@gmail.com）创建
	 * @param sysusergroupid
	 *            用户组权限id
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<SystemUserGroupRole> findSystemUserPermissionValue(String sysusergroupid) {
		List<SystemUserGroupRole> list = null;
		try {
			list = this.find("from SystemUserGroupRole where systemusergroupid = ?", new Object[] { sysusergroupid });
		} catch (DaoException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 
	 * Description: 通过sysusergroupid查询某用户组是否可用，返回用户组对象
	 * 
	 * @Version1.0 2009-3-23 上午12:04:57 李双江（paradise.lsj@gmail.com）创建
	 * @param sysusergroupid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<SystemUserGroup> isSystemUserGroupUsable(String sysusergroupid) {
		List<SystemUserGroup> list = null;
		try {
			list = this.find("from SystemUserGroup where systemusergroupid=?", new Object[] { sysusergroupid });
		} catch (DaoException e) {
			e.printStackTrace();
		}

		return list;
	}
}
